<template>
  <el-dialog
    v-model="centerDialogVisible"
    :title="t('dbms.serviceEdit.updateExpressionTitle')"
    align-center
    width="400px"
    destroy-on-close
    :close-on-click-modal="false"
  >
    <el-form label-position="top">
      <el-form-item :label="t('dbms.serviceEdit.expressionTitle')">
        <el-input type="textarea" :rows="7" v-model="expression" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button-group>
          <el-button @click="centerDialogVisible = false">{{ t('common.close') }}</el-button>
          <el-button type="primary" @click="submit">
            {{ t('common.ok') }}
          </el-button>
        </el-button-group>
      </div>
    </template>
  </el-dialog>
</template>
<script setup lang="ts">
import { ref, toRaw } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'

const { t } = useI18n()
const centerDialogVisible = ref(false)

let callback: Function = () => {}

const expression = ref()

const submit = () => {
  callback(toRaw(expression.value))
  hide()
}

const show = (t: string, cb: Function) => {
  callback = cb
  expression.value = t
  centerDialogVisible.value = true
}

//关闭表单
const hide = () => {
  centerDialogVisible.value = false
}
//暴露方法
defineExpose({ show, hide })
</script>
